<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
    exit('Access Denied');
}

require_once(TIN_APP_PATH . 'include/TinAppController.php');
require_once (TIN_APP_PATH . 'include/Auth.php');
require_once TIN_APP_PATH . "app/view/AssignTable.php";
require_once TIN_APP_PATH . "app/view/AssignView.php";
require_once(TIN_APP_PATH . 'include/utils/page.php');

/** 前台会员中心APP基类 */
class IndexAppController extends TinAppController {
	
	protected $user;
	/** 设置验证是否登录返回的格式,html | json */
	protected $userChkType = "html";
	 
	
	public function __construct() {
        parent::__construct();
        $this->setPageHeader();
        $this->user = Auth::getUserInfo();
        
	    $this->initPage();
	}
	
	private function initPage(){
		//如果不是Ajax请求则默认执行初始界面，根据Action前4位作为判断
		if(strtolower(substr(T::$action, 0,4))=="ajax"){
			T::$tplFile = "public/empty";
			return;
		}
		T::$tpl->set('user',$this->user);
		$this->chkLogin($userChkType);
		//左侧功能菜单
		$this->displayLeftMenu();
	}
	
	/** 验证登录，
	 * @param $returnType 返回类型，html:直接跳转，json:返回Json数据
	 * */
	public function chkLogin($returnType='html'){		
		
		if(!$this->user || $this->user==null){
			$bakurl = urlencode($_SERVER["REQUEST_URI"]);
			if($returnType=='json'){
				T::$tplFile='public/empty';
				$r = array();
				$r['code']='notlogin';
				$r['msg']='对不起！您还没有登录';
				$r['tourl']=''.urldecode($bakurl);
				echo json_encode($r);
			}else{
				header("Location:index.php?".TIN_CTL."=user&tourl=".$bakurl);
			}
            return;
		}
	}
	
	/** 会员中心左侧功能菜单 */
	private function displayLeftMenu() {

	}
	
}//End Class
?>
